package com.example.jdai.jdai.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

import com.example.jdai.jdai.MyApplication;
import com.example.jdai.jdai.config.Config;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hellopyj on 2017/1/9.
 */

public  class BaseData {
    public HashMap<String,String> data=new HashMap<>();
    int count=0;
    public boolean saveAll()
    {
        SharedPreferences sp= MyApplication.applicationContext.getSharedPreferences(Config.SP_NAME, Context.CONTEXT_RESTRICTED);
        SharedPreferences.Editor editor=sp.edit();
        for (Map.Entry<String, String> entry : data.entrySet()) {
            //Log.v("base:"+entry.getKey(),entry.getValue());
            editor.putString(entry.getKey(),entry.getValue());
        }
        editor.commit();
        return true;
    }
    public boolean dataCheck(){
        int i=0;//空白的
        int j=0;//所有
        for (Map.Entry<String, String> entry : data.entrySet()) {
           // Log.v(entry.getKey(),entry.getValue());
            if(entry.getValue().isEmpty())
            i++;
            j++;
        }
        if(j-i>=count) {

            // Log.v("ddddd",i+"");
            //if(STATUS<1)

            return true;
        }
        return false;
    }
    public void clearAll(){
        int i=0;
        for (Map.Entry<String, String> entry : data.entrySet()) {
            // Log.v(entry.getKey(),entry.getValue());
                entry.setValue("");
            i++;
        }

    }

}
